www.gusucode.com > VC++ 对话框中使用打印预览的功能演示-源码程序 > VC++ 对话框中使用打印预览的功能演示-源码程序/code/MainFrm.cpp
//Download by http://www.NewXing.com // MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame(DRAWFUN pDraw,CWnd*pOldW,CWnd* pCallW,BOOL bDirect,LPCTSTR stTitle) { //传递一个绘制函数. // TODO: add member initialization code here Draw=pDraw; pOldWnd=pOldW; pCallWnd=pCallW; bDirectPrint=bDirect; CString ss; if(stTitle!=NULL) ss=_T(stTitle); else { pOldW->GetWindowText(ss); if(!ss.IsEmpty()) ss=ss+_T(" (预览)"); else ss=ss+_T("打印预览"); } if(!Create(NULL,ss,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,CRect(200,200,500,500))) TRACE0("Failed to create view window\n"); } CMainFrame::~CMainFrame() { pOldWnd->ShowWindow(SW_SHOW); } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; CCreateContext context; context.m_pNewViewClass = RUNTIME_CLASS(CWrapperView); context.m_pCurrentFrame = this; context.m_pCurrentDoc = NULL; context.m_pLastView = NULL; m_pView = STATIC_DOWNCAST(CWrapperView, CreateView(&context)); //CreateView(&context); if(m_pView != NULL) { if(!bDirectPrint) m_pView->ShowWindow(SW_SHOW); SetActiveView(m_pView); } SetIcon(pOldWnd->GetIcon(FALSE),FALSE); SetIcon(pOldWnd->GetIcon(TRUE),TRUE); ShowWindow(SW_MAXIMIZE); CWinApp *pApp=AfxGetApp(); pApp->m_pMainWnd=this; if(bDirectPrint) { m_pView->SendMessage(WM_COMMAND, ID_FILE_PRINT); } else { m_pView->OnFilePrintPreview(this); pOldWnd->ShowWindow(SW_HIDE); } return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.dwExStyle &= ~WS_EX_CLIENTEDGE; cs.lpszClass = AfxRegisterWndClass(0); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { // let the view have first crack at the command if (m_pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // otherwise, do default handling return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }